home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 15.2 KB | 495 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPoint.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwodmic_point
- #endif
-
-
- //========================================================================================
- // struct FW_SPoint
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // operator==
- //----------------------------------------------------------------------------------------
-
- FW_Boolean operator==(const FW_SPoint& pt1, const FW_SPoint& pt2)
- {
- return pt1.x == pt2.x && pt1.y == pt2.y;
- }
-
- //----------------------------------------------------------------------------------------
- // operator!=
- //----------------------------------------------------------------------------------------
-
- FW_Boolean operator!=(const FW_SPoint& pt1, const FW_SPoint& pt2)
- {
- return pt1.x != pt2.x || pt1.y != pt2.y;
- }
-
- //----------------------------------------------------------------------------------------
- // operator==
- //----------------------------------------------------------------------------------------
-
- FW_Boolean operator==(const FW_SPoint& pt1, const ODPoint& pt2)
- {
- return FW_FixedToODFixed(pt1.x) == pt2.x && FW_FixedToODFixed(pt1.y) == pt2.y;
- }
-
- //----------------------------------------------------------------------------------------
- // operator!=
- //----------------------------------------------------------------------------------------
-
- FW_Boolean operator!=(const FW_SPoint& pt1, const ODPoint& pt2)
- {
- return FW_FixedToODFixed(pt1.x) != pt2.x || FW_FixedToODFixed(pt1.y) != pt2.y;
- }
-
- //========================================================================================
- // class FW_CPoint
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::FW_CPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint::FW_CPoint(FW_PlatformPoint plfmPoint)
- {
- #ifdef FW_BUILD_WIN
- x = FW_IntToFixed(plfmPoint.x);
- y = FW_IntToFixed(plfmPoint.y);
- #endif
- #ifdef FW_BUILD_MAC
- x = FW_IntToFixed(plfmPoint.h);
- y = FW_IntToFixed(plfmPoint.v);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::FW_CPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint::FW_CPoint(const FW_CPoint &other)
- {
- x = other.x;
- y = other.y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::FW_CPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint::FW_CPoint(const FW_SPoint &point)
- {
- x = point.x;
- y = point.y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::FW_CPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint::FW_CPoint(const ODPoint &odPoint)
- {
- x = FW_ODFixedToFixed(odPoint.x);
- y = FW_ODFixedToFixed(odPoint.y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::FW_CPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint::FW_CPoint(FW_CReadableStream& stream)
- {
- stream >> x >> y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator=(const FW_SPoint &point)
- {
- x = point.x;
- y = point.y;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator=(const FW_CPoint &other)
- {
- x = other.x;
- y = other.y;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator=(const ODPoint &odPoint)
- {
- x = FW_ODFixedToFixed(odPoint.x);
- y = FW_ODFixedToFixed(odPoint.y);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator=(FW_PlatformPoint plfmPoint)
- {
- #ifdef FW_BUILD_WIN
- x = FW_IntToFixed(plfmPoint.x);
- y = FW_IntToFixed(plfmPoint.y);
- #endif
- #ifdef FW_BUILD_MAC
- x = FW_IntToFixed(plfmPoint.h);
- y = FW_IntToFixed(plfmPoint.v);
- #endif
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::Offset
- //----------------------------------------------------------------------------------------
-
- void FW_CPoint::Offset(FW_Fixed xx, FW_Fixed yy)
- {
- x += xx;
- y += yy;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator+=(const FW_SPoint &point)
- {
- x += point.x;
- y += point.y;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator-=(const FW_SPoint &point)
- {
- x -= point.x;
- y -= point.y;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator+=(const ODPoint &odPoint)
- {
- x += FW_ODFixedToFixed(odPoint.x);
- y += FW_ODFixedToFixed(odPoint.y);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator-=(const ODPoint &odPoint)
- {
- x -= FW_ODFixedToFixed(odPoint.x);
- y -= FW_ODFixedToFixed(odPoint.y);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator+(const FW_SPoint &point) const
- {
- return FW_CPoint(x + point.x, y + point.y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator-(const FW_SPoint &point) const
- {
- return FW_CPoint(x - point.x, y - point.y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator+(const ODPoint &odPoint) const
- {
- return FW_CPoint(x + FW_ODFixedToFixed(odPoint.x), y + FW_ODFixedToFixed(odPoint.y));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator-(const ODPoint &odPoint) const
- {
- return FW_CPoint(x - FW_ODFixedToFixed(odPoint.x), y - FW_ODFixedToFixed(odPoint.y));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator-() const
- {
- return FW_CPoint(-x, -y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator+=(FW_CPlatformPoint plfmPoint)
- {
- x += FW_IntToFixed(plfmPoint.X());
- y += FW_IntToFixed(plfmPoint.Y());
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator-=(FW_CPlatformPoint plfmPoint)
- {
- x -= FW_IntToFixed(plfmPoint.X());
- y -= FW_IntToFixed(plfmPoint.Y());
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator+(FW_CPlatformPoint plfmPoint) const
- {
- return FW_CPoint(x + FW_IntToFixed(plfmPoint.X()), y + FW_IntToFixed(plfmPoint.Y()));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator-(FW_CPlatformPoint plfmPoint) const
- {
- return FW_CPoint(x - FW_IntToFixed(plfmPoint.X()), y - FW_IntToFixed(plfmPoint.Y()));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::AsPlatformPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPlatformPoint FW_CPoint::AsPlatformPoint() const
- {
- return FW_CPlatformPoint(FW_FixedToInt(x), FW_FixedToInt(y));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator[]
- //----------------------------------------------------------------------------------------
-
- FW_Fixed& FW_CPoint::operator[](FW_XYSelector selector)
- {
- return * (FW_Fixed *) (selector == FW_kVertical ? &y : &x);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator[]
- //----------------------------------------------------------------------------------------
-
- FW_Fixed FW_CPoint::operator[](FW_XYSelector selector) const
- {
- return * (FW_Fixed *) (selector == FW_kVertical ? &y : &x);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::Map
- //----------------------------------------------------------------------------------------
-
- void FW_CPoint::Map(const FW_SRect& srcRect, const FW_SRect& dstRect)
- {
- FW_Fixed xDelta = x - srcRect.left;
- FW_Fixed yDelta = y - srcRect.top;
-
- FW_Fixed srcSize = srcRect.right - srcRect.left;
- FW_Fixed dstSize = dstRect.right - dstRect.left;
-
- if (srcSize != FW_kFixed0)
- xDelta *= dstSize / srcSize;
-
- x = dstRect.left + xDelta;
-
- srcSize = srcRect.bottom - srcRect.top;
- dstSize = dstRect.bottom - dstRect.top;
-
- if (srcSize != FW_kFixed0)
- yDelta *= dstSize / srcSize;
-
- y = dstRect.top + yDelta;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_Transform
- //----------------------------------------------------------------------------------------
-
- void FW_Transform(Environment* ev, FW_SPoint& pt, ODTransform* transform)
- {
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- * ((ODPoint *) &pt) =
- #endif
- transform->TransformPoint(ev, (ODPoint*) &pt);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_InverseTransform(Environment* ev, FW_SPoint& pt, ODTransform* transform)
- {
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- * ((ODPoint *) &pt) =
- #endif
- transform->InvertPoint(ev, (ODPoint*) &pt);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_TransformCopy
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_TransformCopy(Environment* ev, const FW_SPoint& pt, ODTransform* transform)
- {
- FW_CPoint point(pt);
-
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- * ((ODPoint *) & point) =
- #endif
- transform->TransformPoint(ev, point);
-
- return point;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::InverseTransformCopy
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_InverseTransformCopy(Environment* ev, const FW_SPoint& pt, ODTransform* transform)
- {
- FW_CPoint point(pt);
-
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- * ((ODPoint *) & point) =
- #endif
- transform->InvertPoint(ev, point);
-
- return point;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_TransformPoints
- //----------------------------------------------------------------------------------------
-
- void FW_TransformPoints(Environment* ev, ODTransform* transform, FW_SPoint* pts, long count)
- {
- while (count > 0)
- {
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- ODPoint odpt =
- #endif
- transform->TransformPoint(ev, (ODPoint*) pts);
-
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- pts->x = FW_ODFixedToFixed(odpt.x);
- pts->y = FW_ODFixedToFixed(odpt.y);
- #endif
-
- ++ pts;
- -- count;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_InverseTransformPoints
- //----------------------------------------------------------------------------------------
-
- void FW_InverseTransformPoints(Environment* ev, ODTransform* transform, FW_SPoint* pts, long count)
- {
- while (count > 0)
- {
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- ODPoint odpt =
- #endif
- transform->InvertPoint(ev, (ODPoint*) pts);
-
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- pts->x = FW_ODFixedToFixed(odpt.x);
- pts->y = FW_ODFixedToFixed(odpt.y);
- #endif
-
- ++ pts;
- -- count;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // operator<<
- //----------------------------------------------------------------------------------------
-
- FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_SPoint& point)
- {
- return stream << point.x << point.y;
- }
-
- //----------------------------------------------------------------------------------------
- // operator>>
- //----------------------------------------------------------------------------------------
-
- FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_SPoint& point)
- {
- return stream >> point.x >> point.y;
- }
-